# -*- coding: UTF-8 -*-
from django.http import HttpResponse
import httplib,urllib,urllib2,json,time
import datetime,socket,hashlib
import qcfg,qwater,qwaterdb


def httpSMS(aMobile, aCode):
    print "mobile=",aMobile,"code=",aCode
    tmpPath = "/sms/send?mobile="
    tmpPath += aMobile
    tmpPath += "&tpl_id=21768&tpl_value=%23code%23%3d"
    tmpPath += aCode
    tmpPath += "&dtype=json&key=8b09560bf322c515a75730bf982d5957"
    conn = httplib.HTTPConnection("v.juhe.cn")
    conn.request("GET", tmpPath)
    r1 = conn.getresponse()
    #print r1.status, r1.reason
    tmpRsp = r1.read()
    conn.close()
    
    print tmpRsp
    if(r1.status != 200):
        return None
        
    if(not tmpRsp) or (len(tmpRsp) <= 0):
        return None
        
    tmpJson = json.loads(tmpRsp)
    if(not tmpJson):
        return None
        
    if(not tmpJson.has_key('error_code')):
        return None
        
    if(tmpJson['error_code'] != 0):
        return None
        
    return tmpRsp
 
